//
//  CLmyController.m
//  I-want-go
//
//  Created by dllo on 15/10/30.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "CLmyController.h"
//#import "CLsaveTool.h"
#import "CLguidang.h"
#import "CLinterViewController.h"
#import "CLshenTableCell.h"
#import "CLtool.h"
#import "CLDataBaseHandle.h"
#import "CLscreen.h"
#import "CLmyViewController.h"
@interface CLmyController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, retain)UITableView *liketableView;
@property(nonatomic, retain)NSMutableArray *arr;

@end

@implementation CLmyController
- (void)dealloc {
    [_arr release];
    [_liketableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"我的收藏";
    
    self.liketableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375 * SWIDTH, 667 * SHEIGHT)];
    [self.view addSubview:self.liketableView];
    [_liketableView release];
    
    [self.liketableView reloadData];
    UIImageView *imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"good.png"]];
//    imageView.image=[UIImage imageNamed:@"荷花开.png"];
    [self.liketableView setBackgroundView:imageView];
    [imageView release];
    
    self.liketableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.liketableView.rowHeight = 140 * SHEIGHT;
    self.liketableView.dataSource = self;
    self.liketableView.delegate = self;
    
//    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 1, YES) lastObject];
//    NSString *docPath = [sandBoxPath stringByAppendingPathComponent:@"Disgner/disgner.plist"];
    ////    NSLog(@"%@", self.arr);
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.arr.count == 0) {
        UIAlertController *aleryController = [UIAlertController alertControllerWithTitle:@"无收藏" message:[NSString stringWithFormat:@"您还没有收藏宝贝"] preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:aleryController animated:YES completion:nil];
        UIAlertAction *leftAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            CLmyViewController *myVC = [[CLmyViewController alloc] init
                                        ];
            [self.navigationController pushViewController:myVC animated:YES];
                    }];
        [aleryController addAction:leftAction];
    }
    return self.arr.count;
}
////
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *reuse = @"reuse";
    CLshenTableCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[CLshenTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
    }
    CLguidang *gui = [[CLguidang alloc] init];
//    NSLog(@"%@", self.arr);
    gui =self.arr[indexPath.row];
//
    cell.titleLabel.text = gui.title;
    [cell.phoneImage sd_setImageWithURL:[NSURL URLWithString:gui.image]];
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CLinterViewController *intVC = [[CLinterViewController alloc] init];
    [self.navigationController pushViewController:intVC animated:YES];
    CLguidang *gui = self.arr[indexPath.row];
    
    
    intVC.interId = gui.productId;
}


- (void)viewWillAppear:(BOOL)animated {
    self.arr = [NSMutableArray array];
    //    self.arr = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
    //
    self.arr = [[CLDataBaseHandle shareDataBasaHandle] selectArrMovie];
    [self.liketableView reloadData];
    
    self.tabBarController.tabBar.hidden = YES;
}
//

- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
